-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add comprehensive API for conversation metrics data #11059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add Pydantic response models for metrics data (TokenUsageResponse, CostResponse, etc.)
- Implement GET /api/conversations/{conversation_id}/metrics endpoint
- Add frontend API client method and React Query hook
- Update ConversationInfo model to include basic metrics fields
- Add conversion functions for backend-to-frontend data mapping
- Support both live session metrics and stored conversation metadata
- Include per-service metrics breakdown for detailed analysis
Co-authored-by: openhands <[email protected]>
- Change endpoint from /metrics to /stats for clarity - Remove frontend logic and focus on backend API only - Use ConversationStats to load pre-calculated metrics from pickle files - Eliminate on-the-fly calculation in favor of stored data - Revert unnecessary changes to ConversationInfo and frontend files - API now efficiently reads from conversation_stats.pickle files Co-authored-by: openhands <[email protected]>
|
@OpenHands please fix the failing actions on PR #11059 at branch |
|
I'm on it! rbren can track my progress at all-hands.dev |
- Add test coverage for the new GET /api/conversations/{id}/stats endpoint
- Test successful retrieval with and without metrics data
- Test error handling for missing file store and exceptions
- Ensure proper response format and status codes
- All tests pass with proper mocking of dependencies
Co-authored-by: openhands <[email protected]>
Summary: Fixed Failing GitHub Actions on PR #11059I successfully identified and resolved the failing GitHub Actions on PR #11059 for the ✅ Root Cause IdentifiedThe main failing test was ✅ Issue Resolution
✅ Additional ImprovementsCreated comprehensive test coverage for the new conversation stats API endpoint by adding
✅ Verification Complete
The GitHub Actions should now pass when they run again. The PR includes a new comprehensive API for conversation metrics data with proper test coverage and all dependencies resolved. |
|
Looks like there are a few issues preventing this PR from being merged!
If you'd like me to help, just leave a comment, like Feel free to include any additional details that might help me get this PR into a better state. You can manage your notification settings |
|
This PR is stale because it has been open for 40 days with no activity. Remove the stale label or leave a comment, otherwise it will be closed in 10 days. |
End-user friendly description of the problem this fixes or functionality this introduces.
This PR introduces a new API endpoint that exposes comprehensive metrics data for OpenHands conversations, building on the existing "Display Cost" functionality. Users and developers can now programmatically access detailed cost, token usage, and performance metrics for any conversation through a REST API.
Key Features:
GET /api/conversations/{conversation_id}/metricsSummarize what the PR does, explaining any non-trivial design decisions.
This PR creates a comprehensive API for exposing conversation metrics data that was previously only accessible through the "Display Cost" menu item in the UI.
Backend Changes:
Pydantic Response Models (
openhands/server/data_models/metrics_response.py):TokenUsageResponse: Token breakdown with cache hit/write trackingCostResponse: Cost data with model and timestamp informationResponseLatencyResponse: Performance metrics with response IDsMetricsResponse: Comprehensive metrics containerConversationMetricsResponse: Main response with service breakdownAPI Endpoint (
openhands/server/routes/conversation.py):GET /api/conversations/{conversation_id}/metricsendpointData Model Updates:
ConversationInfoto include basic metrics fieldsFrontend Changes:
TypeScript Types (
frontend/src/api/open-hands.types.ts):API Client (
frontend/src/api/conversation-service/conversation-service.api.ts):getConversationMetrics()method with proper authentication handlingReact Query Hook (
frontend/src/hooks/query/use-conversation-metrics.ts):useConversationMetrics()hook with configurable caching and refetch optionsDesign Decisions:
Testing:
Link of any specific issues this addresses:
This addresses the user request to create an API for exposing metrics data, building on previous analysis of the Display Cost functionality.
To run this PR locally, use the following command:
GUI with Docker:
CLI with uvx: